<?php
namespace app\controller\student;

use app\BaseController;
use app\model\StudentCourse;
use app\model\StudentDiscuss as ModelStudentDiscuss;
use app\model\TeacherDiscuss;
use app\model\Discuss;
use \think\facade\Db;

/**
 * 学生-讨论控制器
 */
class StudentDiscuss extends BaseController
{
    /**
     * 讨论列表
     */
    public function list()
    {
        $courseID=$this->request->param('courseID');
        $studentCourse = StudentCourse::where(["SID"=>$this->user['SID'],"courseID",$courseID]);
        if(empty($studentCourse)){
            return resultError("无权限");
        }
        $discussList = Discuss::where(["courseID"=>$courseID])->select();
        return resultSuccess($discussList);
    }

    /**
     * 讨论详情
     */
    public function discussDetail(){
        $discussID = $this->request->param('discussID');
        $discuss = Discuss::find($discussID)->toArray();
        $studentCourse = StudentCourse::where(["SID"=>$this->user['SID'],"courseID",$discuss['courseID']]);
        if(empty($studentCourse)){
            return resultError("无权限");
        }
        $teacherQuery=Db::table('teacherdiscuss')->where('discussID',$discussID)->buildSql();
        $discussHistory = ModelStudentDiscuss::union($teacherQuery)->where('discussID',$discussID)->order('updateTime','desc')->select()->toArray();
        //历史记录
        $discuss['discussHisroy'] = $discussHistory;
        return resultSuccess($discuss);
    }

    /**
     * 添加讨论内容
     */
    public function addMyDiscuss(){

    }

}
